#!/bin/bash
# description: MySQL数据库分库备份脚本
# date: 2019-07-05
TIME=`date +%F_%H-%M-%S`
# 备份目录
DIR=/backup
# 数据库密码
PASS=123456
PORT=3306
HOST=127.0.0.1

[ -d "$DIR" ] || mkdir -pv ${DIR}

for db in $(mysql -uroot -p${PASS} -P${PORT} -h${HOST} -N -e 'show databases' | grep -Ev '^(Database|information_schema|performance_schema)$')
do 
  mysqldump -uroot -p${PASS} -P${PORT} -h${HOST} -F --single-transaction --master-data=2 -q -B $db | gzip > ${DIR}/${db}_${TIME}.sql.gz
done
